<template>
  <div>
    <h1>房东页面</h1>
    <p v-if="requestReceived">租户请求签署合同。你同意吗？</p>
    <input v-if="requestReceived" v-model="landlordName" placeholder="请输入您的姓名" />
    <button v-if="requestReceived" @click="respondToRequest(true)">同意</button>
    <button v-if="requestReceived" @click="respondToRequest(false)">拒绝</button>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      requestReceived: false,
      landlordName: ''
    };
  },
  created() {
    this.checkRequestStatus();
  },
  methods: {
    async checkRequestStatus() {
      try {
        const response = await axios.get('/api/tenant/request/status');
        this.requestReceived = response.data.requestReceived;
      } catch (error) {
        console.error('检查请求状态失败:', error);
      }
    },
    async respondToRequest(agree) {
      try {
        const response = await axios.get('/api/landlord/response', {
          params: { agree, name: this.landlordName }
        });
        console.log(response.data);
      } catch (error) {
        console.error('响应失败:', error);
      }
    }
  }
};
</script>

<style>
/* Add styles here */
</style>
